import type { PaginationType } from "@/types"
import type { CandidateBase } from "@/types/modules/candidate"
import { reactive, ref } from "vue"
import type { CurrentResume } from "../types"
import type { StatsObject } from "@/components/stat-card/types"

export default function usePageState() {
  // 响应式数据
  const loading = ref<boolean>(false)
  const resumeDialogVisible = ref<boolean>(false)
  const selectedRows = ref<CandidateBase[]>([])
  // 当前选中简历;
  const currentResume = ref<CurrentResume | null>(null)

  // 统计数据
  const stats = ref<StatsObject>({
    total: { value: 156, message: "总候选人" },
    pending: { value: 23, message: "待处理" },
    interview: { value: 18, message: "面试中" },
    offer: { value: 12, message: "已发Offer" },
  })

  // 搜索表单
  const searchForm = reactive({
    candidateName: '',
    jobId: null,
    status: '',
    dateRange: null
  })

  // 分页数据
  const pagination = reactive<PaginationType>({
    current: 1,
    size: 10,
    total: 0
  })

  // 职位列表
  const jobList = ref<{ id: number, title: string }[]>([
    { id: 1, title: 'Java开发工程师' },
    { id: 2, title: '前端开发工程师' },
    { id: 3, title: '产品经理' },
    { id: 4, title: 'UI设计师' }
  ])

  // 表格数据
  const tableData = ref<CandidateBase[]>([
    {
      id: 1,
      candidateName: '张小明',
      email: 'zhangxiaoming@email.com',
      phone: '13800138001',
      avatar: '',
      jobTitle: 'Java开发工程师',
      department: '技术部',
      workExperience: 3,
      expectedSalary: 15,
      status: 'pending',
      applyTime: '2024-01-20T10:30:00',
      matchScore: 85,
      gender: '男',
      age: 28,
      workExperiences: [
        {
          company: '阿里巴巴',
          position: 'Java开发工程师',
          startDate: '2021-03',
          endDate: '2024-01',
          description: '负责电商平台后端开发，参与微服务架构设计'
        }
      ],
      educations: [
        {
          school: '北京大学',
          major: '计算机科学与技术',
          degree: '本科',
          startDate: '2017-09',
          endDate: '2021-06'
        }
      ],
      skills: ['Java', 'Spring Boot', 'MySQL', 'Redis', 'Docker'],
      selfEvaluation: '具有3年Java开发经验，熟悉Spring生态，有大型项目经验。'
    },
    {
      id: 2,
      candidateName: '李小红',
      email: 'lixiaohong@email.com',
      phone: '13800138002',
      avatar: '',
      jobTitle: '前端开发工程师',
      department: '技术部',
      workExperience: 2,
      expectedSalary: 12,
      status: 'interview_invited',
      applyTime: '2024-01-19T14:20:00',
      matchScore: 78,
      gender: '女',
      age: 25,
      workExperiences: [
        {
          company: '腾讯',
          position: '前端开发工程师',
          startDate: '2022-07',
          endDate: '2024-01',
          description: '负责移动端H5开发，熟悉Vue.js和React'
        }
      ],
      educations: [
        {
          school: '清华大学',
          major: '软件工程',
          degree: '本科',
          startDate: '2018-09',
          endDate: '2022-06'
        }
      ],
      skills: ['Vue.js', 'React', 'TypeScript', 'Webpack', 'Node.js'],
      selfEvaluation: '2年前端开发经验，熟悉现代前端框架和工程化工具。'
    }
  ])
  return {
    loading,
    resumeDialogVisible,
    selectedRows,
    currentResume,
    stats,
    searchForm,
    pagination,
    jobList,
    tableData
  }
}
